#include <wx-2.8/wx/gtk/dcclient.h>

#include "cIplCamera.h"

cIplCamera::cIplCamera( wxWindow* parent, wxWindowID id, const wxString& title, const wxPoint& pos, const wxSize& size, long style) : cCamera(parent, id, title, pos, size, style)
{
    cam = new cSTOCStereo(algorithmRadioBox);
    resH = 320;
    resV = 240;	
	isColor = false;
}

void cIplCamera::onExit(wxCommandEvent& event)
{
    delete cam;
    this->Destroy();
}
void cIplCamera::onClose(wxCloseEvent& event)
{
    delete cam;
    this->Destroy();
}


void cIplCamera::onStartCamera(wxCommandEvent& event)
{
    static bool fStart = false;

    if(fStart)
        cam->stopCam();
    else cam->startCam(resH, resV, isColor, extrinsicsTextCtrl->GetValue(), intrinsicsTextCtrl->GetValue());

    fStart ^= true;
}

void cIplCamera::onResolution( wxCommandEvent& event )
{
	if(!resolutionRadioBox->GetSelection())
	{
		resH = 320;
		resV = 240;
		extrinsicsTextCtrl->SetValue(wxT("extrinsics320.yml"));
		intrinsicsTextCtrl->SetValue(wxT("intrinsics320.yml"));

	}
	else
	{
		resH = 640;
		resV = 480;
		extrinsicsTextCtrl->SetValue(wxT("extrinsics.yml"));
		intrinsicsTextCtrl->SetValue(wxT("intrinsics.yml"));
	}
}

void cIplCamera::onSaveVideo( wxCommandEvent& event )
{
    static bool fStartSaveVideo = false;

    if(fStartSaveVideo)
        cam->stopSaveVideo();
    else cam->startSaveVideo(saveTextCtrl->GetValue(), leftVCheckBox->IsChecked(), rightVCheckBox->IsChecked(), stereoVCheckBox->IsChecked());

    fStartSaveVideo ^= true;
}

void cIplCamera::onScreenshot( wxCommandEvent& event )
{
    cam->saveScreenshot(saveTextCtrl->GetValue());
}

void cIplCamera::onStereoRadioBox( wxCommandEvent& event )
{

}
void cIplCamera::onCalculateStereo( wxCommandEvent& event )
{
    static bool fStartCalculateStereo = false;

    if(!fStartCalculateStereo)
    {
		long sad, nDisp;
		SADChoice->GetStringSelection().ToLong(&sad);
		dispChoice->GetStringSelection().ToLong(&nDisp);
        cam->startCalculateStereo(nDisp, sad);
    }
    else cam->stopCalculateStereo();

    fStartCalculateStereo ^= true;
}
